package com.xushu.lessons.all;

import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.annotation.*;

import java.util.Map;

@Configuration	// spring.xml
@ComponentScan	// <component-scan  base-packages="">
public class MainStart {
	public static void main(String[] args) {

	  // spring容器 spring上下文   bean创建、依赖注入 过程
		AnnotationConfigApplicationContext ctx =
				new AnnotationConfigApplicationContext(MainStart.class);

		/**/
		/* UserService userService = (UserService) ctx.getBean("userService");*/


		// 手动完成bean创建过程
		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

		// 读取配置类
		AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(beanFactory);
		reader.register(MainStart.class);

		// invokeBeanFactoryPostProcessors
		// 解析配置类
		AnnotatedGenericBeanDefinition beanDefinition=(AnnotatedGenericBeanDefinition)beanFactory.getBeanDefinition("mainStart");
		if(beanDefinition.getMetadata().hasAnnotation(ComponentScan.class.getName())){

			Map<String, Object> annotationAttributes = beanDefinition.getMetadata().getAnnotationAttributes(ComponentScan.class.getName());

		}


		// 扫描
		ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(beanFactory);
		scanner.scan("com.xushu.all");


		//UserService userService = (UserService) beanFactory.getBean("userService");

		beanFactory.preInstantiateSingletons();

	}





}
